home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
13288
/
13288.xpi
/
content
/
preference.js
< prev
next >
Wrap
Text File
|
2010-01-24
|
10KB
|
229 lines
const DiskCacheBranch = "browser.cache.disk.parent_directory";
var stmPref = {
gPrefs: Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch),
gBlockHotkey: "", //keycode+key+modifiers
gPageLockHotkey: "",
gBosskeyHidekey: "",
gBosskeyShowkey: "",
gDiskCacheDefaultDir: false,
gCacheDelUserBranch: false,
onLoad: function() {
var b = this.gPrefs.getBoolPref("extensions.stm.pagelock.enable");
document.getElementById("b.pagelock.enable").setAttribute("disabled", b==true?"false":"true");
this.setTabColorAttribute(b);
this.onOpenInNewTab();
b = this.gPrefs.getBoolPref("extensions.stm.block.enable");
document.getElementById("b.block.enable").setAttribute("disabled", b==true?"false":"true");
b = this.gPrefs.getBoolPref("extensions.stm.bosskey.enable");
document.getElementById("b.bosskey.enable").setAttribute("disabled", b==true?"false":"true");
b = this.gPrefs.getBoolPref("browser.cache.disk.enable");
document.getElementById("b.cachedisk.enable").setAttribute("disabled", b==true?"false":"true");
//get hotkey
this.getHotkey("pagelock.hotkey");
this.getHotkey("block.hotkey");
this.getHotkey("bosskey.hidekey");
this.getHotkey("bosskey.showkey");
//cache
this.setCacheDirLabel();
document.getElementById("pane1.tabbox").selectedIndex = this.gPrefs.getIntPref("extensions.stm.selectedTab");
},
getHotkey: function(pname) {
var list = this.gPrefs.getCharPref("extensions.stm." + pname).split("|:|");
document.getElementById("e." + pname).value = list[0];
},
setCacheDirLabel: function() {
var label = document.getElementById("diskcache.pos");
label.value = this.getCurrentCacheDir();
},
setUserCacheDir: function(poslabel, alertlabel) {
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, document.getElementById("stm.prefstringmanager").getString("diskcache.selectdir"), nsIFilePicker.modeGetFolder);
var fpShow = fp.show();
if (fpShow == nsIFilePicker.returnOK) {
document.getElementById(poslabel).value = fp.file.path + "\\Cache";
var e = document.getElementById(alertlabel);
if (fp.file.path + "\\Cache" != this.getCurrentCacheDir())
e.hidden=false;
else
e.hidden=true;
}
},
setDefaultCacheDir: function(poslabel, alertlabel) {
var ddir = this.getDefaultCacheDir();
document.getElementById(poslabel).value = ddir;
var e = document.getElementById(alertlabel);
if (ddir != this.getCurrentCacheDir())
e.hidden = false;
else
e.hidden = true;
},
getCurrentCacheDir: function() {
var cdir;
var cache_service = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
var cvisitor = {visitDevice: function(device, aDeviceInfo) {
if (device == "disk") {
var des = aDeviceInfo.usageReport;
var start = des.indexOf("<tt>") + 4;
var stop = des.indexOf("</tt>");
cdir = des.substring(start,stop).replace(/^\s+/g,"").replace(/\s+$/g,"");
}
}}
cache_service.visitEntries(cvisitor);
return cdir;
},
getDefaultCacheDir: function() {
return Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("ProfD", Components.interfaces.nsIFile).path + "\\Cache";
},
restartApp: function() {
this.updateCacheDir();
var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(Components.interfaces.nsIAppStartup);
appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
},
hideRestart: function(ename) {
document.getElementById(ename).hidden = true;
},
updateCacheDir: function() {
var userdir = document.getElementById("diskcache.pos").value;
if (userdir == this.getCurrentCacheDir()) return;
if (userdir == this.getDefaultCacheDir())
this.gPrefs.deleteBranch(DiskCacheBranch);
else
this.gPrefs.setCharPref(DiskCacheBranch, userdir.replace(/\\Cache$/g, ""));
},
onOK: function() {
if (this.gBlockHotkey != "")
this.gPrefs.setCharPref("extensions.stm.block.hotkey", this.gBlockHotkey);
if (this.gPageLockHotkey != "")
this.gPrefs.setCharPref("extensions.stm.pagelock.hotkey", this.gPageLockHotkey);
if (this.gBosskeyHidekey != "")
this.gPrefs.setCharPref("extensions.stm.bosskey.hidekey", this.gBosskeyHidekey);
if (this.gBosskeyShowkey != "")
this.gPrefs.setCharPref("extensions.stm.bosskey.showkey", this.gBosskeyShowkey);
this.updateCacheDir();
this.setPane1SelectedTab();
},
setPane1SelectedTab: function() {
this.gPrefs.setIntPref("extensions.stm.selectedTab", document.getElementById("pane1.tabbox").selectedIndex);
},
onReset: function() {
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var strings = document.getElementById("stm.prefstringmanager");
if(!prompts.confirm(null, null, strings.getString('prefs.onreset'))) return false;
var count = { value : 0 };
var childList = this.gPrefs.getChildList("extensions.stm.", count);
for(var i = 0; i < count.value; i++) {
if (this.gPrefs.prefHasUserValue(childList[i])) this.gPrefs.clearUserPref(childList[i]);
}
var ffprefs = new Array("browser.tabs.loadBookmarksInBackground",
"browser.tabs.tabMinWidth",
"browser.sessionstore.max_tabs_undo",
"browser.tabs.loadInBackground",
"browser.link.open_newwindow",
"browser.link.open_newwindow.restriction",
"browser.tabs.loadDivertedInBackground",
"browser.tabs.closeButtons",
"browser.tabs.closeWindowWithLastTab",
"browser.cache.disk.enable",
"browser.cache.disk.capacity",
"browser.cache.disk.parent_directory",
"browser.cache.memory.enable",
"browser.cache.offline.enable",
"browser.cache.offline.capacity",
"browser.urlbar.maxRichResults"
);
for(var i = 0; i < ffprefs.length; i++) {
if (this.gPrefs.prefHasUserValue(ffprefs[i])) this.gPrefs.clearUserPref(ffprefs[i]);
}
window.location.reload(false);
},
syncOpenBHSInNewTab: function(value) {
this.gPrefs.setBoolPref("browser.search.openintab", value);
},
onOpenInNewTab: function() {
var checked1 = document.getElementById("e.openURLBarInNewTab").checked;
var checked2 = document.getElementById("e.openBHSInNewTab").checked;
document.getElementById("e.newTabForeBack").disabled=!checked1 & !checked2;
},
onPagelockEnable: function(pcheckbox) {
var b = document.getElementById("b.pagelock.enable");
b.setAttribute("disabled", !pcheckbox.checked);
this.setTabColorAttribute(pcheckbox.checked);
},
setTabColorAttribute: function(pagelock_enable) {
var element = document.getElementById("e.pagelock.enableTabColor");
document.getElementById("e.pagelock.tabColor").disabled = pagelock_enable==true ? !element.checked : true;
element = document.getElementById("e.pagelock.enableTabTxtColor");
document.getElementById("e.pagelock.tabTxtColor").disabled = pagelock_enable==true ? !element.checked : true;
},
onPLEnableTabColor: function(pcheckbox) {
document.getElementById("e.pagelock.tabColor").disabled = !pcheckbox.checked;
},
onPLEnableTabTxtColor: function(pcheckbox) {
document.getElementById("e.pagelock.tabTxtColor").disabled = !pcheckbox.checked;
},
/* toggle toolbar button */
toggleButton: function(bname) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
wm.getMostRecentWindow("navigator:browser").stmM.toggleToolbarButton(bname);
},
onBlockEnable: function(pcheckbox) {
var b = document.getElementById("b.block.enable");
b.setAttribute("disabled", !pcheckbox.checked);
},
onBosskeyEnable: function(pcheckbox) {
var b = document.getElementById("b.bosskey.enable");
b.setAttribute("disabled", !pcheckbox.checked);
},
changeHotkey: function(labelid) {
this.gBlockHotkey = "";
const dialog = "chrome://supertabmode/content/key.xul";
var features = "chrome,titlebar,toolbar,centerscreen,modal";
window.openDialog(dialog, "", features, labelid);
},
onCacheDiskEnable: function(pcheckbox) {
var b = document.getElementById("b.cachedisk.enable");
b.setAttribute("disabled", !pcheckbox.checked);
},
} //var end